package org.dyz.banana.controllers;

import org.dyz.banana.service.KafkaProducerServiceImpl;
import org.dyz.banana.vo.JsonRequest;
import org.dyz.banana.vo.JsonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
public class TestProducerController {

    private static final Logger log= LoggerFactory.getLogger(TestProducerController.class);
    @Autowired
    private KafkaProducerServiceImpl kafkaProducerServiceImpl;
    // 发送消息
    @RequestMapping(value = "/kafka/msg",method = RequestMethod.POST)
    public JsonResponse sendMessage(@RequestBody JsonRequest request) {
        if(request!=null){
            String topic = request.getTopic();
            String message = request.getMessage();
            return kafkaProducerServiceImpl.sendMessage(topic,message);
        }else{
            return JsonResponse.fail();
        }

    }

}
